1 /*
2 * File: Autopilot.c
3 *
4 * Code generated for Simulink model 'Autopilot'.
5 *
6 * Model version : 1.152
7 * Simulink Coder version : 8.5 (R2013b) 08-Aug-2013
8 * C/C++ source code generated on : Mon Feb 03 08:13:57 2014
9 *
10 * Target selection: ert.tlc
11 * Embedded hardware selection: 32-bit Embedded Processor
12 * Code generation objectives: Unspecified
13 * Validation result: Not run
14 */
15
16 #include "Autopilot.h"
17 #include "Autopilot_private.h"
18
19 const slBus1 Autopilot_rtZslBus1 = {
20 0.0, /* altRate */
21 0.0, /* alpha */
22 0.0, /* beta */
23 0.0, /* airspeed */
24 0.0 /* alt */
25 } ; /* slBus1 ground */
26
27 const slBus2 Autopilot_rtZslBus2 = {
28 0.0, /* phi */
29 0.0, /* theta */
30 0.0, /* psi */
31 0.0, /* p */
32 0.0, /* q */
33 0.0 /* r */
34 } ; /* slBus2 ground */
35
36 /* Block states (auto storage) */
37 D_Work_Autopilot Autopilot_DWork;
38
39 /* External inputs (root inport signals with auto storage) */
40 ExternalInputs_Autopilot Autopilot_U;
41
42 /* External outputs (root outports fed by signals with auto storage) */
43 ExternalOutputs_Autopilot Autopilot_Y;
44
45 /* Model step function */
46 void Autopilot_step(void)
47 {
48 /* local block i/o variables */
49 real_T rtb_phi;
50 real_T rtb_theta;
51 real_T rtb_q;
52 real_T rtb_r;
53 real_T rtb_airspeed;
54 real_T rtb_psi;
55 real_T rtb_p;
56 real_T rtb_alt;
57 real_T rtb_altRate;
58
59 /* BusSelector: '<Root>/Bus Selector4' incorporates:
60 * Inport: '<Root>/Inertial'
61 */
62 rtb_phi = Autopilot_U.Inertial.phi;
63 rtb_psi = Autopilot_U.Inertial.psi;
64 rtb_p = Autopilot_U.Inertial.p;
65 rtb_theta = Autopilot_U.Inertial.theta;
66 rtb_q = Autopilot_U.Inertial.q;
67 rtb_r = Autopilot_U.Inertial.r;
68
69 /* BusSelector: '<Root>/Bus Selector3' incorporates:
70 * Inport: '<Root>/Air Data'
71 */
72 rtb_alt = Autopilot_U.AirData.alt;
73 rtb_altRate = Autopilot_U.AirData.altRate;
74 rtb_airspeed = Autopilot_U.AirData.airspeed;
75
76 /* ModelReference: '<Root>/Roll_Autopilot' */
77 roll_ap(&rtb_phi, &rtb_psi, &rtb_p, &rtb_airspeed, &Autopilot_U.APeng,
78 &Autopilot_U.HDGmode, &Autopilot_U.HDGref, &Autopilot_U.TurnKnob,
79 &Autopilot_Y.AileronCmd, &(Autopilot_DWork.Roll_Autopilot_DWORK1.rtb),
80 &(Autopilot_DWork.Roll_Autopilot_DWORK1.rtdw), 1.0, 1.0, 3.0, 0.015);
81
82 /* ModelReference: '<Root>/Pitch_Autopilot' */
83 pitch_ap(&rtb_phi, &rtb_theta, &rtb_q, &rtb_r, &rtb_alt, &rtb_altRate,
84 &rtb_airspeed, &Autopilot_U.APeng, &Autopilot_U.ALTMode,
85 &Autopilot_U.ALTRef, &Autopilot_U.PitchWheel,
86 &Autopilot_Y.ElevatorCmd,
87 &(Autopilot_DWork.Pitch_Autopilot_DWORK1.rtb),
88 &(Autopilot_DWork.Pitch_Autopilot_DWORK1.rtdw), 2.0, 0.5, 2.0);
89
90 /* ModelReference: '<Root>/Yaw_Damper' */
91 yaw_damper(&rtb_phi, &rtb_r, &rtb_airspeed, &Autopilot_U.APeng,
92 &Autopilot_Y.RudderCmd, &(Autopilot_DWork.Yaw_Damper_DWORK1.rtb),
93 1.0);
94 }
95
96 /* Model initialize function */
97 void Autopilot_initialize(void)
98 {
99 /* Registration code */
100
101 /* states (dwork) */
102 (void) memset((void *)&Autopilot_DWork, 0,
103 sizeof(D_Work_Autopilot));
104
105 /* external inputs */
106 (void) memset((void *)&Autopilot_U, 0,
107 sizeof(ExternalInputs_Autopilot));
108 Autopilot_U.AirData = Autopilot_rtZslBus1;
109 Autopilot_U.Inertial = Autopilot_rtZslBus2;
110 Autopilot_U.HDGref = 0.0;
111 Autopilot_U.TurnKnob = 0.0;
112 Autopilot_U.ALTRef = 0.0;
113 Autopilot_U.PitchWheel = 0.0;
114
115 /* external outputs */
116 Autopilot_Y.AileronCmd = 0.0;
117 Autopilot_Y.ElevatorCmd = 0.0;
118 Autopilot_Y.RudderCmd = 0.0;
119
120 /* Model Initialize fcn for ModelReference Block: '<Root>/Pitch_Autopilot' */
121 pitch_ap_initialize(&(Autopilot_DWork.Pitch_Autopilot_DWORK1.rtb),
122 &(Autopilot_DWork.Pitch_Autopilot_DWORK1.rtdw));
123
124 /* Model Initialize fcn for ModelReference Block: '<Root>/Roll_Autopilot' */
125 roll_ap_initialize(&(Autopilot_DWork.Roll_Autopilot_DWORK1.rtb),
126 &(Autopilot_DWork.Roll_Autopilot_DWORK1.rtdw));
127
128 /* Model Initialize fcn for ModelReference Block: '<Root>/Yaw_Damper' */
129 yaw_damper_initialize(&(Autopilot_DWork.Yaw_Damper_DWORK1.rtb));
130
131 /* Start for ModelReference: '<Root>/Pitch_Autopilot' */
132 pitch_ap_Start(&(Autopilot_DWork.Pitch_Autopilot_DWORK1.rtdw));
133 }
134
135 /*
136 * File trailer for generated code.
137 *
138 * [EOF]
139 */
140
|